package com.example.basicquestions.questions.最长公共子串;
import java.util.*;
/**
 * @author liw
 * @date 2023-03-10
 *
 */
public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String str1 = scanner.nextLine();
        String str2 = scanner.nextLine();

        String minStr = str1.length() >= str2.length() ? str1 : str2;
        String maxStr = minStr.equals(str1) ? str2 : str1;
        String resultStr = "";
        for (int i = 0; i<minStr.length() - 1; i++){
            for(int j = i + 1; j < minStr.length(); j++){
                String s = minStr.substring(i,j);
                if(maxStr.contains(s) && s.length()>resultStr.length()){
                    resultStr = s;
                }
            }
        }
        System.out.println(resultStr);
    }
}
